<?php

require_once 'actions/_user_settings.cls.php';
require_once 'ActionFramework/formcomponents/date.php';
require_once 'ActionFramework/formcomponents/list.php';
require_once 'ActionFramework/formcomponents/password.php';
require_once 'views/costum/language.php';


class UserSettingsForms {
	
	private $form;
	private $view;
	private $signup;
	
	public function __construct($form, $view, $signup=false) {
		$this->form = $form;
		$this->view = $view;
		$this->signup = $signup;
	}
	
	public function echo_profile_form() {
		
		echo '<div class="form-layout">';
		
			$first_name = $this->form->generate(new TextField(_UserSettingsAction::INPUT_FIRST_NAME));
			$last_name = $this->form->generate(new TextField(_UserSettingsAction::INPUT_LAST_NAME));
			$gender = $this->form->generate(new ListDropDownField(_UserSettingsAction::INPUT_GENDER));
			$date_of_birth = $this->form->generate(new DateField(_UserSettingsAction::INPUT_DATE_OF_BIRTH));
			$about_yourself = $this->form->generate(new TextAreaField(_UserSettingsAction::INPUT_ABOUT_YOURSELF));
			$facebook = $this->form->generate(new TextField(_UserSettingsAction::INPUT_FACEBOOK));
			$email_when_new_match = $this->form->generate(new HiddenField(_UserSettingsAction::INPUT_EMAIL_WHEN_NEW_MATCH));
			if ($this->signup) {
				$invisible = $this->form->generate(new HiddenField(_UserSettingsAction::INPUT_INVISIBLE));
			} else {
				$invisible = $this->form->generate(new CheckboxField(_UserSettingsAction::INPUT_INVISIBLE));
			}
			$newsletter = $this->form->generate(new CheckboxField(_UserSettingsAction::INPUT_NEWSLETTER));
			$languages = $this->form->generate(new LanguageListField(_UserSettingsAction::INPUT_KNOWN_LANGUAGES));
			
			if ($this->view->user) {
				$first_name->set_initial_value($this->view->user->first_name);
				$last_name->set_initial_value($this->view->user->last_name);
				$gender->set_initial_value($this->view->user->gender);
				$date_of_birth->set_initial_value($this->view->user->date_of_birth);
				$about_yourself->set_initial_value($this->view->user->about_yourself);
				$facebook->set_initial_value($this->view->user->facebook);
				$email_when_new_match->set_initial_value($this->view->user->email_when_new_match);
				$invisible->set_initial_value($this->view->user->invisible);
				$newsletter->set_initial_value($this->view->user->newsletter);
				$languages->set_initial_value($this->view->user->known_languages);
			} else if ($this->signup) {
				$first_name->set_initial_value($this->view->name);
				$email_when_new_match->set_initial_value('0');
				$invisible->set_initial_value('0');
			}
			
			echo $first_name->label();
			echo $last_name->label();
			echo $gender->label(); 
			echo $date_of_birth->label();
			echo $about_yourself->label();
			echo $facebook->label();
			echo $email_when_new_match;
			if ($this->signup) {
				echo $invisible;
			} else {
				echo $invisible->label();
			}
			echo $newsletter->label();
			echo $languages->wrap_in_div('lang-formcomponent')->label();
			
			echo "<div style='clear:both'></div>";
			
		echo '</div>';
		
	}
	
	public function echo_criteria_form() {
		
		echo '<div class="form-layout">';
		
			$unknown_languages = $this->form->generate(new LanguageLevelListField(FinishSignupAction::INPUT_UNKNOWN_LANGUAGES_AND_LEVELS));

			if ($this->view->user) {
				$unknown_languages->set_initial_value($this->view->user->unknown_languages_and_levels);
			}		
				
			echo $unknown_languages->label();
			
			/*
			$choices = array_combine(
				$this->form->get_input(SaveCriteriaAction::INPUT_PARTNER_GENDER)->get_choices(),
				array("Doesn't matter", 'Men', 'Women')
			);
			echo $this->form->generate(new ListDropdownField(FinishSignupAction::INPUT_PARTNER_GENDER, $choices))->label();
			*/
			
			echo "<div style='clear:both'></div>";
				
		echo '</div>';
		
	}
	
}